
    $(document).ready(function () {
   
  
       $.ajax({
           url: "/cfarmc_fund/res_partner", type: "POST", data: {LIMIT:'0'},success: function (result) {                  
              
               $("select[id='dep_data']").empty();      //清空  
               var modelList = eval('(' + result + ')');
               if (modelList && modelList.length != 0) {
                   var option = "<option value='0'>全部机构</option>";
                   $("select[id='dep_data']").append(option);
                   for (var i = 0; i < modelList.length; i++) {
                       var option = "<option value=\"" + modelList[i].id+ "\"";
                      
                       option += ">" + modelList[i].name + "</option>";   
                       $("select[id='dep_data']").append(option);
                   }
               } 
              page_load();			   
             }
			
         });
  

        $("#button1").click(function () {
		 console.log('------22222----------')
         page_load();
	       
         });
        $("#date_start1 option").each(function() 
		{
	     var date = new Date();
	     var year = date.getFullYear();
          if($(this).val()==year)
		  {
             $(this).prop('selected',true);
          }
         });

        $("#date_end1 option").each(function()
		 {
		  var date = new Date();
	      var Month= date.getMonth() + 1
           if($(this).val()==Month)
		   {
       	       $(this).prop('selected',true);
		   }
		 }); 

		
        
    });
    function page_load()
	{
		

            var date_end = $('#date_end1').val();
            var date_start = $('#date_start1').val();
            var dep_data = $("#dep_data option:selected").val();
			
            var fh_load=getCookie("fh_load");			
			if(fh_load=="1")
			{
             console.log('-11112-',fh_load)
             date_start = getCookie("date_start");			 
             date_end = getCookie("date_end");
             dep_data = getCookie("dep_data");
			 

			 
            $("#date_start1 option").each(function() 
            {
             ///console.log('-dep_data2-',dep_data)	
             var year = date_start;
             if($(this).val()==year)
             {
             $(this).prop('selected',true);
             }
            });

            $("#date_end1 option").each(function()
		    {

	         var Month= date_end
             if($(this).val()==Month)
		      {
       	       $(this).prop('selected',true);
		      }
		    })
			
			console.log('-dep_data1-',dep_data)
            $("#dep_data option").each(function()
		    {
				
			  console.log('-dep_data2-',dep_data)				
	          var fhdata= dep_data
              if($(this).val()==fhdata)
		      {
       	       $(this).prop('selected',true);
		      }
		    })


			 setCookie("fh_load","0","d20");
			 setCookie("date_start","","d20");			 
			 setCookie("date_end","","d20");
			 setCookie("dep_data","","d20");			 
			}			
            var oTab1 = document.getElementById('tab1');
            $("#tab1").empty();  
            var fhifconsumables = "0";			
            $.ajax({
                url: "../../cfarmc_fund/publice_property_report", type: "POST", data: {LIMIT: 0, N: 0, date_start: date_start, date_end: date_end, dep_data: dep_data, fhifconsumables: fhifconsumables}, success: function (result) {
                    result = unescape(result.replace(/\\u/g, '%u'));
                    var modelList = eval('(' + result + ')');
					var taltol= taltol_td(modelList);
					$("#tatol1").html(formatMoney(taltol,3,"￥"));	
					
					$("#fhxj").html(formatMoney(modelList[0].fhxj,3,"￥"));					
					$("#fhyh").html(formatMoney(modelList[0].fhyh,3,"￥"));					
					$("#fhtatol").html(formatMoney(modelList[0].fhtatol,3,"￥"));							
					
					$("#fhmonitor").html(modelList[0].fhorgan);	
					$("#fhdate").html(modelList[0].fhdate);	
					$("#fhhr").html(modelList[0].fhhr);	



						
                    fhname="";
                    fhk=0;	
					
                     for (var i = 0; i < modelList.length; i++) {
  
                        fhk=fhk+1;
                        console.log('-----account1-----',modelList[i].account);
						if(fhname!=modelList[i].account)							
						{
						fhname=modelList[i].account;
						var oTr = document.createElement('tr'); 
                        var linnerHTML = '';
						fhname=modelList[i].account;
						var  k=add_td_by_fhname_yes(modelList,fhname)      
						console.log('-k-')
						console.log(k)						
                        var oTr = document.createElement('tr'); 
                        var linnerHTML = '';
						if(k!=1)
						{
                        linnerHTML = linnerHTML + " <td  style='text-align:center;' rowspan="+(k+1)+">" + modelList[i].account+"</td>";
						}
						else
						{

						if(modelList[i].account=="空")
						{
						linnerHTML = linnerHTML + " <td  style='text-align:center;' rowspan=2 >" + modelList[i].account+"</td>";
						}
						else
						{
						 linnerHTML = linnerHTML + " <td  style='text-align:center;' rowspan=2 >" + modelList[i].account+"</td>";
						}
                        ///add_oTab1_appendChild(oTab1,"0.0");						
						}
					
                        linnerHTML = linnerHTML + " <td>" + modelList[i].fh_account_002+"</td>";
                        linnerHTML = linnerHTML + " <td>" + modelList[i].name+"</td>";
                        linnerHTML = linnerHTML + " <td align='right'>" + formatMoney(modelList[i].fhdebit,3,"￥")+"</td>";			
                        oTr.innerHTML = linnerHTML;
                        oTab1.appendChild(oTr);
						
						if(k==1)
						{
							if(modelList[i].account!="空")
							{
					         var taltol=taltol_td_by_fhname(modelList,fhname)	
							 add_oTab1_appendChild(oTab1,taltol);
							}								
						}						
						
						
						}
						else
						{
							
                        var oTr = document.createElement('tr'); 
                        var linnerHTML = '';
                        linnerHTML = linnerHTML + "";
                        linnerHTML = linnerHTML + " <td >" + modelList[i].fh_account_002+"</td>";
                        linnerHTML = linnerHTML + " <td >" + modelList[i].name+"</td>";
                        linnerHTML = linnerHTML + " <td align='right'>" + formatMoney(modelList[i].fhdebit,3,"￥")+"</td>";			
                        oTr.innerHTML = linnerHTML;
                        oTab1.appendChild(oTr);

						var  k=add_td_by_fhname_yes(modelList,fhname)
						//最后一项目
						if(fhk==(k))
						{
					     var taltol=taltol_td_by_fhname(modelList,fhname)	
					     add_oTab1_appendChild(oTab1,taltol);	
							
						}
						
						}
                    }
		
					var taltol=taltol_td_by_fhname(modelList,fhname)	
					add_oTab1_appendChild(oTab1,taltol);

					
					
					
                  var fhifconsumables = "1";
                  $.ajax({
                  url: "../../cfarmc_fund/publice_property_report", type: "POST", data: { LIMIT: 0, N: 0, date_start: date_start, date_end: date_end, dep_data: dep_data, fhifconsumables: fhifconsumables}, success: function (result) {
                    result = unescape(result.replace(/\\u/g, '%u'));
                    var modelList2 = eval('(' + result + ')');

	
					
					 var oTr = document.createElement('tr'); 
					 var linnerHTML = '';
                     var taltol= taltol_td(modelList2);
                     linnerHTML = linnerHTML + '<td    colspan="3"   align="left">三、本期支出合计:</td>';

                     linnerHTML = linnerHTML +'<td align="right">'+formatMoney(taltol,3,"￥")+'</td>';
                   
                     oTr.innerHTML = linnerHTML;
                     oTab1.appendChild(oTr);
					 var oTr = document.createElement('tr'); 
					 var linnerHTML = '';
                     linnerHTML = linnerHTML + '<td   style="text-align:center;" bgcolor="#96b97d">会计科目</td>';

                     linnerHTML = linnerHTML +'<td   style="text-align:center;" bgcolor="#96b97d">明细科目</td>';
                     linnerHTML = linnerHTML +'<td   style="text-align:center;" bgcolor="#96b97d">摘要说明</td>';
                     linnerHTML = linnerHTML +'<td   style="text-align:center;" bgcolor="#96b97d">金额</td>';
                     oTr.innerHTML = linnerHTML;
                     oTab1.appendChild(oTr);

                    fhname2="";
                    fhk2=0;	
                     for (var i = 0; i < modelList2.length; i++) {
                        console.log('-----account1-----',modelList2[i].account);  
                        fhk2=fhk2+1;             
						if(fhname2!=modelList2[i].account)							
						{
						fhname2=modelList2[i].account;
						var oTr = document.createElement('tr'); 
                        var linnerHTML = '';
						fhname2=modelList2[i].account;
						var  k2=add_td_by_fhname_yes(modelList2,fhname2)      
						console.log('-k2-')
						console.log(k2)						
                        var oTr = document.createElement('tr'); 
                        var linnerHTML = '';
						if(k2!=1)
						{
                        linnerHTML = linnerHTML + " <td style='text-align:center;'  rowspan="+(k2+1)+">" + modelList2[i].account+"</td>";
						}
						else
						{
					   	if(modelList2[i].account=="空")
						{
                        linnerHTML = linnerHTML + " <td  style='text-align:center;' rowspan=2>" + modelList2[i].account+"</td>";							
						}
						else
						{
                        linnerHTML = linnerHTML + " <td  style='text-align:center;' rowspan=2>" + modelList2[i].account+"</td>";
						}							
						}
					
                        linnerHTML = linnerHTML + " <td >" + modelList2[i].fh_account_002+"</td>";
                        linnerHTML = linnerHTML + " <td >" + modelList2[i].name+"</td>";
                        linnerHTML = linnerHTML + " <td  align='right'>" +formatMoney(modelList2[i].fhdebit,3,"￥") +"</td>";			
                        oTr.innerHTML = linnerHTML;
                        oTab1.appendChild(oTr);
						if(k2==1)
						{
						if(modelList2[i].account!="空")
						{
						var taltol=taltol_td_by_fhname(modelList2,fhname2)
                        add_oTab1_appendChild(oTab1,taltol);
						}								
						}
						
						}
						else
						{
							
                        var oTr = document.createElement('tr'); 
                        var linnerHTML = '';
                        linnerHTML = linnerHTML + "";
                        linnerHTML = linnerHTML + " <td>" + modelList2[i].fh_account_002+"</td>";
                        linnerHTML = linnerHTML + " <td>" + modelList2[i].name+"</td>";
                        linnerHTML = linnerHTML + " <td  align='right'>" +formatMoney(modelList2[i].fhdebit,3,"￥") +"</td>";			
                        oTr.innerHTML = linnerHTML;
                        oTab1.appendChild(oTr);

						var  k2=add_td_by_fhname_yes(modelList2,fhname2)
						//最后一项目
						if(fhk2==(k2+1))
						{
						var taltol=taltol_td_by_fhname(modelList2,fhname2)	
						add_oTab1_appendChild(oTab1,taltol);		
							
						}
						
						}
                    }
		
					var taltol=taltol_td_by_fhname(modelList2,fhname2)	
					add_oTab1_appendChild(oTab1,taltol);
		
                   var oTr = document.createElement('tr'); 
                   var linnerHTML = '';
                   linnerHTML = linnerHTML + '<td    colspan="3"   align="left">四、本期结存货币资金合计</td>';
                   linnerHTML = linnerHTML + '<td  align="right">'+formatMoney(modelList2[0].fhtatol_bq,3,"￥")+'</td>';
		
                   oTr.innerHTML = linnerHTML;
                   oTab1.appendChild(oTr);		            
	
                   var oTr = document.createElement('tr'); 
                   var linnerHTML = '';

                   linnerHTML = linnerHTML + '<td    colspan="3"   align="left">现金</td>';
                   linnerHTML = linnerHTML + '<td  align="right">'+formatMoney(modelList2[0].fhxj_bq,3,"￥")+'</td>';
		
                   oTr.innerHTML = linnerHTML;
                   oTab1.appendChild(oTr);

                   var oTr = document.createElement('tr'); 
                   var linnerHTML = '';
                   linnerHTML = linnerHTML + '<td   colspan="3"   align="left">银行存款</td>';
                   linnerHTML = linnerHTML + '  <td  align="right">'+formatMoney(modelList2[0].fhyh_bq,3,"￥")+'</td>';			
                   oTr.innerHTML = linnerHTML;
                   oTab1.appendChild(oTr);
			
                   
                 }
				
                });	 					
					
					

                }
				
            });		
		
		
	}
	
	
	
	function add_td_by_fhname_yes(modelList,fhname)
    {
	  var k=0;
      for (var i = 0; i < modelList.length; i++) 
	  {
	   if(fhname==modelList[i].account)
	   {
		k=k+1;
       }               
      }
     return	 k; 
   }
   
	function taltol_td_by_fhname(modelList,fhname)
    {
	  var k=0.0;
      for (var i = 0; i < modelList.length; i++) 
	  {
	   if(fhname==modelList[i].account)
	   {
		k=k+parseFloat(modelList[i].fhdebit);
       }               
      }
     return	 k; 
   }   
   
	function taltol_td(modelList)
    {
	  var k=0.0;
      for (var i = 0; i < modelList.length; i++) 
	  {
	   if(1==1)
	   {
		k=k+parseFloat(modelList[i].fhdebit);
       }               
      }
     return	 k; 
   }    
	function add_oTab1_appendChild(oTab1,fhvalue)
	{	
	
        console.log('-----fhvalue----',fhvalue);
        if(1==1)
		{			
		var oTr = document.createElement('tr'); 
        var linnerHTML = '';
		linnerHTML = linnerHTML + "";
        linnerHTML = linnerHTML + " <td>总计</td>";
        linnerHTML = linnerHTML + " <td>一级科目合计</td>";
        linnerHTML = linnerHTML + " <td  align='right'>"+formatMoney(fhvalue,3,"￥") +"</td>";						
        oTr.innerHTML = linnerHTML;
        oTab1.appendChild(oTr);	
		}
	}	

   function formatMoney(number, places, symbol, thousand, decimal) {
        number = number || 0;
        places = !isNaN(places = Math.abs(places)) ? places : 2;
        symbol = symbol !== undefined ? symbol : "$";
        thousand = thousand || ",";
        decimal = decimal || ".";
        var negative = number < 0 ? "-" : "",
            i = parseInt(number = Math.abs(+number || 0).toFixed(places), 10) + "",
            j = (a = i.length) > 3 ? a % 3 : 0;
        return symbol + negative + (j ? i.substr(0, j) + thousand : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + thousand) + (places ? decimal + Math.abs(number - i).toFixed(places).slice(2) : "");
}

	